/**
 * 2024/01/01 - 2024/12/31
 **/
package com.snail.camunda.engin.process.controller;

import com.snail.camunda.engin.process.dto.DeleteProcessDTO;
import com.snail.camunda.engin.process.dto.DoneDTO;
import com.snail.camunda.engin.process.dto.ProcessDeployDTO;
import com.snail.camunda.engin.process.dto.TodoDTO;
import com.snail.camunda.engin.process.manager.ProcessManager;
import com.snail.camunda.engin.process.vo.DoneVO;
import com.snail.camunda.engin.process.vo.HistoryActivityVO;
import com.snail.camunda.engin.process.vo.TodoVO;
import com.snail.starter.commons.page.PageQO;
import com.snail.starter.commons.page.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: (zg)
 * @Date: 2024/12/12 13:20
 * @Version: 1.0.0
 */
@Api(tags = {"流程管理"})
@Validated
@RestController
@RequestMapping("/process")
public class ProcessController {

    @Resource
    ProcessManager flowManager;

    @PostMapping
    @ApiOperation("部署流程")
    public String deploy(@Validated @RequestBody ProcessDeployDTO processDeploy) {
        return flowManager.deploy(processDeploy);
    }

    @PostMapping("/{processId}/start")
    @ApiOperation("启动流程")
    public String start(@Validated @PathVariable("processId") @Length(min = 1, max = 3) String processId) {
        return flowManager.start(processId);
    }

    @PostMapping("/{processId}/stop")
    @ApiOperation("停止流程")
    public boolean stop(@PathVariable("processId") String processId, @RequestBody DeleteProcessDTO deleteProcess) {
        return flowManager.stop(processId, deleteProcess);
    }

    @PutMapping("/{processId}/commit")
    @ApiOperation("提交流程")
    public String commit(@PathVariable("processId") String processId) {
        return flowManager.start(processId);
    }

    @DeleteMapping("/{processId}/rollback")
    @ApiOperation("回退流程")
    public String rollback(@PathVariable("processId") String processId) {
        return flowManager.start(processId);
    }

    @DeleteMapping("/{processId}/del")
    @ApiOperation("删除流程")
    public String del(@PathVariable("processId") String processId) {
        return flowManager.start(processId);
    }

    @DeleteMapping("/todo")
    @ApiOperation("待办")
    public PageVO<TodoVO> todo(@RequestBody PageQO<TodoDTO> page) {
        return flowManager.todo(page);
    }

    @DeleteMapping("/done")
    @ApiOperation("已办")
    public PageVO<DoneVO> done(@RequestBody PageQO<DoneDTO> page) {
        return flowManager.done(page);
    }

    @DeleteMapping("/{processInstanceId}/historic")
    @ApiOperation("流程执行过程")
    public List<HistoryActivityVO> history(@PathVariable("processInstanceId") String processId){
        return flowManager.history(processId);
    }
}